package com.example.innospace.demos.web.mapper;

import com.example.innospace.demos.pojo.dto.StudentDTO;
import com.example.innospace.demos.pojo.dto.StudentPageQueryDTO;
import com.example.innospace.demos.pojo.entity.Admin;
import com.example.innospace.demos.pojo.entity.Student;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface StudentMapper {

    @Select("select * from student where student_id=#{studentId}")
    Student findById(@Param("studentId") String studentId);


    /**
     * 修改学生个人信息
     *
     * @param student
     */


     void update(@Param("student") Student student);

     @Update("update student set avatar=#{avatarUrl} where student_id=#{studentId}")
    void updateAvatar(@Param("studentId") String studentId, @Param("avatarUrl") String avatarUrl);
     @Select("select avatar from student where student_id=#{studentId}")
    String getAvatar(@Param("studentId") String studentId);

     @Select("select * from student where student_id=#{studentId}")
    Student getStudentInfo(@Param("studentId")String studentId);

     @Select("select password from student where student_id=#{studentId}")
    String getpassword(@Param("studentId")String studentId);

    @Update("update student set password=#{newPassword} where student_id=#{studentId}")
    void updatePassword(@Param("newPassword") String newPassword, @Param("studentId") String studentId);

    @Insert("insert into student (name,student_id,password,college,major,phone_number,email,enrollmentDate,inclass,bank_card,education_level,gender,qq_number,avatar,status) values " +
            "(#{name},#{studentId},#{password},#{college},#{major},#{phoneNumber},#{email},#{enrollmentDate},#{inclass},#{bankCard},#{educationLevel},#{gender},#{qqNumber},#{avatar},#{status})")
    void insert(StudentDTO studentDTO);

    @Update("update student set status=#{status} where student_id=#{studentId}")
    void studentstartOrstop(@Param("status")Integer status, @Param("studentId") String studentId);


    void batchDeleteStudents(@Param("studentIds") List<String> studentIds);

    Page<Admin> pageQuery(StudentPageQueryDTO studentPageQueryDTO);
@Update("update student set project_id=#{id}  where student_id=#{studentId}")
    void setProjectId( @Param("studentId")String studentId, @Param("id")Integer id);


    @Select("select * from student where project_Id=#{id}")
    List<Student> findByprojectId(@Param("id")int id);

    @Update("update student set project_id=null where project_id=#{projectId}")
    void deleteByProject(Integer projectId);


    @Select("select project_id from student where student_id=#{studentId}")
    Integer getProjectId(@Param("studentId") String studentId);


    @Update("update studnet set password={s} where student_id=#{studentId}")
    void setPassWord(@Param("s")String s, @Param("studentId") String studentId);
}
